//引入路由组件
// import Home from '@/pages/Home'
// import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// 引入二级路由组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
export default [
    {
        path: '/center',
        component: Center,
        meta: { show: true },
        //二级路由组件
        children:[
            {
                path:'myorder',
                component:MyOrder
            },
            {
                path:'grouporder',
                component:GroupOrder
            },
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: { show: true }
    },
    {
        path: '/pay',
        component: Pay,
        meta: { show: true },
        beforeEnter: (to, from, next) => {
            if(from.path == '/trade' || from.path =='/'){
                next()
            }else{
                next(false)
            }
        }
    },
    {
        path: '/trade',
        component: Trade,
        meta: { show: true },
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //去交易页面,必须是从购物车而来
            if (from.path == '/shopcart' || from.path =='/' || from.path == '/login') {
                next()
            }else{
                next(false)
            }
        }
    },
    {
        path: '/shopcart',
        component: ShopCart,
        meta: { show: true }
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: AddCartSuccess,
        meta: { show: true }
    },
    {
        path: '/detail/:skuid',
        component: Detail,
        meta: { show: true }
    },
    {
        path: '/home',
        component: ()=>import("@/pages/Home"),
        meta: { show: true }
    },
    {
        name: 'search',
        path: '/search/:keyword?',
        component: ()=>import("@/pages/Search"),
        meta: { show: true },
        // props:true
        // props:{a:1,b:2}
        props: ($route) => ({ keyword: $route.params.keyword, k: $route.query.k })

    },
    {
        path: '/login',
        component: Login,
        meta: { show: false }

    },
    {
        path: '/register',
        component: Register,
        meta: { show: false }

    },
    {
        path: '*',
        redirect: '/home'
    }
]